# -*- coding: utf-8 -*-
# ----------------------------
# @Time    : 2022/5/29 8:08 PM
# @Author  : changqingai
# @FileName: 06-load_csv_data.py
# ----------------------------

import pandas as pd
import tensorflow as tf


# ********* 1.读单个文件 ************
pd_df = pd.read_csv("./datasets/csv_1.csv", sep=",", header=1, encoding="utf-8")
ds = tf.data.Dataset.from_tensor_slices(dict(pd_df))
for data in ds.take(2):
    print("data:", data)


# ********* 2.make_csv_dataset *******
file_paths = ["./datasets/csv_1.csv", "./datasets/csv_2.csv"]
ds = tf.data.experimental.make_csv_dataset(file_paths, batch_size=4, label_name="id")
for feature_batch, label_batch in ds.take(5):
    print(feature_batch, label_batch.numpy())
    print("features:")
    for key, value in feature_batch.items():
        print(key, ":", value)
